

using System;
using System.Web;
using System.Text.RegularExpressions;

namespace JTC.MiniCommerce.Core {
  
  public class CoreUtility {
  
    #region Methods
  
    #region Public

    /// <summary>
    /// Strips the HTML.
    /// </summary>
    /// <param name="htmlString">The HTML string.</param>
    /// <param name="htmlPlaceHolder">The HTML place holder.</param>
    /// <returns></returns>
    public static string StripHtml(string htmlString, string htmlPlaceHolder) {
      string pattern = @"<(.|\n)*?>";
      string sOut = Regex.Replace(htmlString, pattern, htmlPlaceHolder);
      sOut = sOut.Replace("&nbsp;", "");
      sOut = sOut.Replace("&amp;", "&");
      sOut = sOut.Replace("&gt;", ">");
      sOut = sOut.Replace("&lt;", "<");
      return sOut;
    }

    /// <summary>
    /// Parses the camel cased string to proper.
    /// </summary>
    /// <param name="sIn">The s in.</param>
    /// <returns></returns>
    public static string ParseCamelToProper(string sIn) {
      char[] letters = sIn.ToCharArray();
      string sOut = "";
      foreach(char c in letters) {
        if(c.ToString() != c.ToString().ToLower()) {
          //it's uppercase, add a space
          sOut += " " + c.ToString();
        }
        else {
          sOut += c.ToString();
        }
      }
      return sOut;
    }

    /// <summary>
    /// Generates a random string.
    /// </summary>
    /// <param name="length">The length.</param>
    /// <returns></returns>
    public static string GenerateRandomString(int length) {
      string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
      string randomString = string.Empty;
      if (length > 0) {
        Random rnd = new Random();
        for (int i = 0; i < length; i++) {
          randomString += chars[rnd.Next(chars.Length)];
        }
      }
      return randomString;
    }

    #endregion
    
    #endregion
    
  }
}
